package com.wyz.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wyz.model.Goods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author wk
 * @desc
 * @date 2024/7/26 15:19
 */
public interface GoodsMapper extends BaseMapper<Goods> {
    // 自定义方法，用于获取用户和角色的联合查询结果
    @Select("SELECT u.*, r.goods_type as goods_type FROM t_goods u JOIN t_goods_type r ON u.goods_typeid = r.goods_typeid")
    List<Map<String, Object>> selectGoodsWithType();
//    @Select("SELECT u.*, r.goods_type FROM t_goods u JOIN t_goods_type r ON u.goods_typeid = r.goods_typeid WHERE u.good_barcode LIKE CONCAT('%', #{condition}, '%') or u.goods_name LIKE CONCAT('%', #{condition}, '%') or u.goods_sprecification LIKE CONCAT('%', #{condition}, '%') or u.good_remark LIKE CONCAT('%', #{condition}, '%') or ORDER BY u.goods_barcode ASC")
//    List<Map<String, Object>> selectGoodsWithGoodsTypeLikeCondition(String condition,String sort);
    @Select("SELECT u.*, r.goods_type FROM t_goods u " +
        "LEFT JOIN t_goods_type r ON u.goods_typeid = r.goods_typeid " +
        "WHERE u.goods_barcode LIKE CONCAT('%', #{condition}, '%') " +
        "OR u.goods_name LIKE CONCAT('%', #{condition}, '%') " +
        "OR u.goods_sprecification LIKE CONCAT('%', #{condition}, '%') " +
        "OR u.goods_remark LIKE CONCAT('%', #{condition}, '%') " +
        "ORDER BY #{sort} DESC")
    List<Map<String, Object>> selectGoodsWithGoodsTypeLikeCondition(String condition,String sort);

    @Select("SELECT u.*, r.goods_type FROM t_goods u LEFT JOIN t_goods_type r ON u.goods_typeid = r.goods_typeid WHERE u.goods_typeid = #{id}")
    List<Map<String, Object>> getGoodsById(@Param("id") Integer id);
}
